package de.baumann.browser.fragments


import android.content.Intent
import android.support.v7.widget.LinearLayoutManager
import android.view.View
import com.chad.library.adapter.base.BaseQuickAdapter
import de.baumann.browser.R
import de.baumann.browser.activitys.order.RechargeOrderDetailActivity
import de.baumann.browser.adapter.RechargeOrderAdapter
import de.baumann.browser.api.net.vo.Order
import de.baumann.browser.base.BaseOdinFragment
import de.baumann.browser.iview.IRechargeOrderView
import de.baumann.browser.present.RechargeOrderPresenter
import de.baumann.browser.utils.ViewUtil
import kotlinx.android.synthetic.main.fragment_recharge_order.*

/**
 *@author:
 *@date:2019/7/4 19:56
 *@discription: 充值订单
 */
class RechargeOrderFragment : BaseOdinFragment<IRechargeOrderView, RechargeOrderPresenter>(), IRechargeOrderView {

    private lateinit var rechargeOrderAdapter: RechargeOrderAdapter

    companion object {
        val instance: RechargeOrderFragment by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) {
            RechargeOrderFragment()
        }
    }

    override fun getLayout(): Int {
        return R.layout.fragment_recharge_order
    }

    override fun initView(view: View) {
        rvRechargeOrder.layoutManager = LinearLayoutManager(context)
        rechargeOrderAdapter = RechargeOrderAdapter(R.layout.recycler_item_order)
        rechargeOrderAdapter.emptyView = ViewUtil.emptyView(mContext)
        rvRechargeOrder.adapter = rechargeOrderAdapter
        rechargeOrderAdapter.onItemClickListener = BaseQuickAdapter.OnItemClickListener { adapter, _, position ->
            val order = adapter!!.getItem(position) as Order
            val intent = Intent(context, RechargeOrderDetailActivity::class.java)
            intent.putExtra("orderId", order.incomeId.toString())
            startActivity(intent)
        }
    }

    override fun createPresenter(): RechargeOrderPresenter {
        return RechargeOrderPresenter()
    }

    override fun createView(): IRechargeOrderView {
        return this
    }

    override fun initData() {
        getPresenter().rechargeRecord()
    }

    override fun setRechargeRecord(orders: List<Order>?) {
        rechargeOrderAdapter.setNewData(orders)
    }
}
